package alfred.mdp.messages.worker;

import alfred.mdp.Majordomo;
import alfred.mdp.messages.ProtocolMessage;
import org.zeromq.ZFrame;
import org.zeromq.ZMsg;

/**
 * Reply<br>
 * Frame 0: Empty frame<br>
 * Frame 1: "MDPW01" (six bytes, representing MDP/Worker v0.1)<br>
 * Frame 2: 0x03 (one byte, representing REPLY)<br>
 * Frame 3: Client address (envelope stack)<br>
 * Frame 4: Empty (zero bytes, envelope delimiter)<br>
 * Frames 5+: Reply body (opaque binary)<br>
 */
public class Reply extends ProtocolMessage {

    public Reply(ZFrame clientAddress, ZMsg message) {
        super(
                Majordomo.EMPTY,
                Majordomo.PROTOCOL_WORKER_V,
                Majordomo.Worker.REPLY,
                clientAddress,
                Majordomo.EMPTY
        );
        getZMsg().addAll(message);
    }


    public ZMsg getBody() {
        return getSubMsg(5);
    }

    public ZFrame getClientAddress() {
        return get(3);
    }

}
